﻿<?php
if(!defined('IN_PHPSCUP'))exit('hacking'); 

class FilesApp extends BaseApp
{

    function index($dir_file='')
    {
		if(!isset($_GET['v']))
		{
		 $_GET['v'] = '';
		}
		$v = $_GET['v'];
		if($dir_file)
		{
		  $v = $dir_file;
		}
        $v || $v = UPFILE_PATH;
	    $up_path = preg_replace("/(.*)\/([^\/]+)/is","\\1",$v);

	    $this_path = ROOT_PATH.'/'.$v;		
	    $lang_db = $this->get_file($v);	
        $this->assign('up_path', $up_path);
        $this->assign('this_path', $this_path);		
        $this->assign('lang_db', $lang_db);
		
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('file_list.view.php');
    }



    function del()
    {
		
		$file = $_GET['v'];
        $v = $file;
		$file= ROOT_PATH . '/'  . $file;
		
		$filename = basename($file);
		$dir = str_replace(array($filename),array(''),$file);
		$v = str_replace(array($filename),array(''),$v);
	    if(!is_dir($file)&&file_exists($file))
		{
		     del_file($file);	
		}
		
		$this->index($v);
    }




    function get_file($dir)
	{
	    $dir_hand = opendir(ROOT_PATH.'/'.$dir);
	    while($file=readdir($dir_hand))
	   {
		    $rs['path']="$dir/$file";
		    if(is_file(ROOT_PATH.'/'."$dir/$file"))
		    {
			$rs['type']="file";
			$rs['icon']="data/images/file.gif";
			$array[]=$rs;
		    }
		    elseif( $file!="." && $file!=".." && is_dir(ROOT_PATH.'/'."$dir/$file") )
		    {
			$rs['type']="dir";
			$rs['icon']="data/images/folder.gif";
			$array[]=$rs;
		    }
	   }
	   return $array;
    }


}


?>